'''
Created on 30.01.2013

@author: Marko
'''

def percentile(data, percentile):
    percentile = percentile

    array = data
    
    array.sort()

    r = (percentile / 100.0) * (len(array) + 1.0)

    rindex = int(r)
    if rindex <= 0:
        rindex = 1
    
    if rindex <= len(array) - 1:
        return  r % 1 * (array[rindex] - array[rindex - 1]) + array[rindex - 1]
    else:
        return array[len(array) - 1]
